package org.rendao.user
{
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	
	import org.rendao.entity.UserDetail;
	import org.rendao.service.UserService;

	public class UserViewPM
	{
		public var dm:UserViewDM;
		
		public function getAllUsers():void {
			var onGet:Function = function(users:Array):void {
				dm.userList = new ArrayCollection(users);
			};
			UserService.instance.getAllUser(onGet);
		}
		
		public function saveUser(user:UserDetail):void {
			var onSave:Function = function(savedUser:UserDetail):void {
				dm.user = savedUser;
				Alert.show("保存成功");
				getAllUsers();
			};
			UserService.instance.saveUser(user, onSave);
		}
		
		public function deleteUser(id:String):void {
			var onDelete:Function = function():void {
				Alert.show("刪除成功");
				dm.user = new UserDetail();
				getAllUsers();
			};
			UserService.instance.deleteUser(id, onDelete);
		}
	}
}